class Solution
{
public:
    vector<int> twoOutOfThree(vector<int> &nums1, vector<int> &nums2, vector<int> &nums3)
    {
        unordered_set<int> nums1Set(nums1.begin(), nums1.end());
        unordered_set<int> nums2Set(nums2.begin(), nums2.end());
        unordered_set<int> nums3Set(nums3.begin(), nums3.end());
        unordered_set<int> result;
        for (int num : nums1Set)
        {
            if (nums2Set.count(num) || nums3Set.count(num))
            {
                result.insert(num);
            }
        }
        for (int num : nums2Set)
        {
            if (nums1Set.count(num) || nums3Set.count(num))
            {
                result.insert(num);
            }
        }
        for (int num : nums3Set)
        {
            if (nums1Set.count(num) || nums2Set.count(num))
            {
                result.insert(num);
            }
        }
        return {result.begin(), result.end()};
    }
};